package com.stone.track

import android.annotation.SuppressLint
import java.text.SimpleDateFormat
import java.time.LocalDateTime
import java.util.*

/**
 * @description track-demo-android
 * @author msp
 * @time 2021/3/15
 */
object DateUtils {

    const val format: String = "yyyyMMddHHmmss"

    fun getDateInterval(startStr: String, endStr: String, format: String): Long {
        val sf = SimpleDateFormat(format, Locale.CHINA)
        val startDate = sf.parse(startStr)
        val endDate = sf.parse(endStr)
        if (startDate == null || endDate == null) {
            throw IllegalArgumentException("getDateInterval : startStr or endStr Illegal")
        }
        return getDateInterval(startDate, endDate)
    }

    fun getDateInterval(startDate: Date, endDate: Date): Long {
        val interval = (endDate.time - startDate.time) / 1000
        return interval
    }

}